/**
 * This class is the implementation of the LinkedStack class.  This class 
 * is needed by the HaHaTester class.  This class creates a stack in the 
 * form of a LinkedList.  A nested Node class for the LinkedList is nested.
 */
public class LinkedStack
{
  /**
  	* This is the node class for the LinkedStack class.
	*/
	protected class Node
	{
		public Object data;
		public Node under;
		
	  /**
		* Creates a default Node
		*
		* @exception	none - No exceptions thrown
		* @see			"No burrowed code"
		*/
		public Node()
		{
			this(null,null);
		}//End of DVC
		
	  /**
		* This method creates a specific Node
		*
		* @param			data - link to the data that the node stores
		* @param			under - link to the next node in the list
		* @exception	none - No exceptions thrown
		* @see			"No burrowed code"
		*/
		public Node(Object data, Node under)
		{
			this.data = data;
			this.under = under;
		}//End of EVC
	}//End of Node Class
	
	private Node top;

  /**
	* This method creates an empty LinkedStack
	*
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
	public LinkedStack()
	{
		this.top = null;
	}//End of DVC
	
  /**
	* This method adds a node to the top of the stack.
	*
	* @param			temp - Object that is to be added
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
/*ans bl*/
	public void push(Object temp)
	{
		this.top = new Node(temp, this.top);
	}//End of push()
/*ans ab*/

  /**
	* This method returns and removes the top
	* item from the stack.
	*
	* @return		Object - The object that was at the top of the LinkedStack
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
	public Object pop()
	{
//ans bl
		Object temp = this.top.data;
		this.top = this.top.under;
		
		return temp;
//ans ab
	}

  /**
	* This method checks if the LinkedStack is empty.
	*
	* @return		boolean - Value of if the LinkedStack is empty or not.
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
	public boolean isEmpty()
	{
		return this.top == null;
	}//End of isEmpty()

  /**
	* This method creates an empty LinkedStack
	*
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/
	public void popAll()
	{
		this.top = null;
	}//End of popAll()
	
  /**
	* This method overrides Objects toString() and 
	* creates a string that displays the nodes in
	* the LinkedStack.
	*
	* @return		String - The output string of toString().
	* @exception	none - No exceptions thrown
	* @see			"No burrowed code"
	*/	
	@Override
	public String toString()
	{
		if(isEmpty())
			return "";
		else
		{
			String result = "";
			for (Node cur = this.top;cur != null;cur = cur.under)
				result += cur.data +"\n";
			
			return result;
		}
	}//End of toString()
	
}//End of LinkedStack